<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: table_mobile_setting.php 31281 2012-08-03 02:29:27Z zhangjie $
     */

    if (!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }

    class table_cloud_express extends discuz_table {

        public function __construct() {
            $this->_table = 'cloud_express';
            $this->_pk = 'caeid';

            parent::__construct();
        }

        //插入数据库
        public function insert($arr) {
            return DB::insert($this->_table, $arr, true);
        }

        //更新数据库
        public function update($caeid, $data) {
            $caeid = intval($caeid);
            if (!$data) {
                return;
            }
             return DB::update($this->_table, $data, DB::field($this->_pk, $caeid));
        }

        //查找某条记录
        public function fetch_info($caeid) {
            $caeid = intval($caeid);
            return DB::fetch_first("SELECT * FROM %t WHERE caeid=%d", array($this->_table, $caeid));
        }

        //查询所有limt数据
        public function fetch_all_by_caid_limit($caid,$start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .' where caid='.$caid.
                ' ORDER BY ' . DB::order('createtime', 'desc')  .
                DB::limit($start, $limit));
        }

        //查询count
        public function fetch_all_by_caid_count($caid) {
            $caid = intval($caid);
            return DB::fetch_first('SELECT count(caeid) as counts FROM ' . DB::table($this->_table).' where caid='.$caid);
        }


        // 删除
        public function delete_by_id($caeid) {
            return DB::query("DELETE FROM %t WHERE caeid=%d", array($this->_table, $caeid));
        }

        public function fetch_by_province_all($caid,$province){
            return DB::fetch_all("SELECT * FROM ". DB::table($this->_table)." where caid=".$caid." and express_area like '%".$province."%'");
        }

    }